

'''
    需求：用户名唯一化 pickle了解

'''


# 请求接口获取响应数据
print(1)
import requests
import hashlib
import random
import pickle

#序列化 存数据
'''
a= 1
fp=open('D:\\1.txt','wb')
pickle.dump(a,fp)
fp.close
'''
#反序列化 取数据
fp=open('D:\\1.txt','rb')
b= pickle.load(fp)
fp.close()
print(999,b)
#b=b+1

#用户名进行添加数字做后缀 保持用户名唯一
fp=open('D:\\1.txt','wb')
pickle.dump(b+1,fp)
fp.close
fp.close


username= 'kkkkk' + str(b)
req= requests.post(url='http://101.42.247.45:8080/register/',
                  data='{"username":"%s","password":"12345678abc","email":"wxh@qq.com"}' %(username,))

print(9,req.text)


m5= hashlib.md5()
m5.update('12345678abc'.encode('utf-8'))
pwd= m5.hexdigest()
print(pwd)



req= requests.post(url='http://101.42.247.45:8080/register/',
                  data='{"username":"%s","password":"%s","email":"wxh@qq.com"}' %(username,pwd,))

#接口响应的字符串内容
print(111,req.text)
#http协议状态码
print(2,req.status_code)

print(req.json())#dict类型
print(type(req.json()))#dict类型
print(req.json()['code'])